package com.college.products.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.college.common.pojo.ao.ProductsType;
import com.college.common.pojo.dto.products.AddProductsTypeDTO;
import com.college.common.pojo.dto.products.QueryProductsTypeDTO;
import com.college.common.pojo.dto.products.UpdateProductsTypeDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.products.mapper.ProductsTypeMapper;
import com.college.products.service.ProductsTypeService;
import com.github.pagehelper.page.PageMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品分类 服务实现类
 * @author 小C工作室
 * @since 2025-02-22
 */
@Service
public class ProductsTypeServiceImpl extends ServiceImpl<ProductsTypeMapper, ProductsType> implements ProductsTypeService {
    @Autowired
    private ProductsTypeMapper productsTypeMapper;

    @Override
    public List<ProductsType> queryList(QueryProductsTypeDTO queryProductsTypeDTO) {
        return productsTypeMapper.queryList(queryProductsTypeDTO);
    }

    @Override
    public List<ProductsType> queryListPage(QueryProductsTypeDTO queryProductsTypeDTO, PageParamRequest pageParamRequest) {
        PageMethod.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        return productsTypeMapper.queryList(queryProductsTypeDTO);
    }

    @Override
    public CommonResult<String> addProductsType(AddProductsTypeDTO addProductsTypeDTO) {
        return this.save(addProductsTypeDTO)? CommonResult.success("商品分类新增成功") : CommonResult.failed("商品分类新增失败");
    }

    @Override
    public CommonResult<String> updateProductsType(UpdateProductsTypeDTO updateProductsTypeDTO) {
        ProductsType productsType = ObjectUtil.objectCopyProperties(updateProductsTypeDTO, ProductsType.class);
        return this.updateById(productsType) ? CommonResult.success("商品分类修改成功") : CommonResult.failed("商品分类修改失败");
    }
}
